
package com.gitee.flow.service;

import com.gitee.flow.entity.HiTaskinstEntity;
import com.gitee.jmash.common.lock.DistributedLock;
import com.gitee.jmash.core.orm.cdi.JpaTenantService;
import com.gitee.jmash.core.transaction.JakartaTransaction;
import jakarta.enterprise.inject.Typed;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import jakarta.transaction.Transactional.TxType;
import jakarta.validation.executable.ValidateOnExecution;
import java.util.Set;

/**
 * act_hi_taskinst写服务.
 *
 * @author <a href="mailto:service@crenjoy.com">crenjoy</a>
 */
@Typed(HiTaskinstWrite.class)
@Transactional(TxType.REQUIRED)
@JpaTenantService
@ValidateOnExecution
public class HiTaskinstWriteBean extends HiTaskinstReadBean
    implements HiTaskinstWrite, JakartaTransaction {

  @Inject
  DistributedLock lock;

  @Override
  @PersistenceContext(unitName = "WriteFlow")
  public void setEntityManager(EntityManager entityManager) {
    this.tem.setEntityManager(entityManager, true);
  }

  @Override
  public boolean setAssignee(String entityId, String assignee) {
    HiTaskinstEntity entity = findById(entityId);
    if(null == entity) {
      return false;
    }
    entity.setAssignee(assignee);
    hiTaskinstDao.merge(entity);
    return true;
  }

  @Override
  public HiTaskinstEntity delete(String entityId) {
    HiTaskinstEntity entity = hiTaskinstDao.removeById(entityId);
    return entity;
  }

  @Override
  public Integer batchDelete(Set<String> entityIds) {
    int i = 0;
    for (String entityId : entityIds) {
      hiTaskinstDao.removeById(entityId);
      i++;
    }
    return i;
  }
  

}
